@set WORK_DIR=%~dp0

@echo %GOPATH%

@IF "%1" == "" call :gen_static_data_code & cd %WORK_DIR% & goto :exit

@IF "%1" == "all" call :all & cd %WORK_DIR% & goto :exit

@IF "%1" == "make_go" call :make_go & cd %WORK_DIR% & goto :exit

@IF "%1" == "gen_extend" call :gen_extend & cd %WORK_DIR% & goto :exit

@IF "%1" == "gen_static_data_json" call :gen_static_data_json & cd %WORK_DIR% & goto :exit

@IF "%1" == "gen_static_data_code" call :gen_static_data_code & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-enum-go" call :protoc-gen-enum-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-rpc-go" call :protoc-gen-rpc-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-myjson-go" call :protoc-gen-myjson-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-myjson-ts" call :protoc-gen-myjson-ts & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-mgo-go" call :protoc-gen-mgo-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-pbex-go" call :protoc-gen-pbex-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-pbex-ts" call :protoc-gen-pbex-ts & cd %WORK_DIR% & goto :exit

@IF "%1" == "protoc-gen-client-model-go" call :protoc-gen-client-model-go & cd %WORK_DIR% & goto :exit

@IF "%1" == "trans_file_to_utf8" call :trans_file_to_utf8 & cd %WORK_DIR% & goto :exit

@IF "%1" == "clean-log" call :clean-log & cd %WORK_DIR% & goto :exit

@echo unsupported operate [%1]

@goto :exit


:all
@echo install all begin
@call :make_go
@call :gen_extend
@call :gen_static_data_json
@call :gen_static_data_code
@call :protoc-gen-enum-go
@call :protoc-gen-rpc-go
@call :protoc-gen-myjson-go
@call :protoc-gen-myjson-ts
@call :protoc-gen-mgo-go
@call :protoc-gen-pbex-go
@call :protoc-gen-pbex-ts
@call :trans_file_to_utf8
@echo install all end
@goto :exit


:make_go
@echo install [make_go] begin
copy %WORK_DIR%\make_go.bat %GOPATH%\bin\make_go.bat
@echo install [make_go] end
@goto :exit


:gen_extend
@echo install [gen_extend] begin
cd %WORK_DIR%\gen_extend
go install
go generate
go test -v
@echo install [gen_extend] end
@goto :exit


:gen_static_data_json
@echo install [gen_static_data_json] begin
cd %WORK_DIR%\gen_static_data_json
go install
go generate
go test -v
@echo install [gen_static_data_json] end
@goto :exit


:gen_static_data_code
@echo install [gen_static_data_code] begin
cd %WORK_DIR%\gen_static_data_code
go install
go generate
go test -v
go test -v ./sd
@echo install [gen_static_data_code] end
@goto :exit


:protoc-gen-enum-go
@echo install [protoc-gen-enum-go] begin
cd %WORK_DIR%\protoc-gen-enum-go
go install
go generate .\enum
go test -v
@echo install [protoc-gen-enum-go] end
@goto :exit


:protoc-gen-rpc-go
@echo install [protoc-gen-rpc-go] begin
cd %WORK_DIR%\protoc-gen-rpc-go
go install
cd rpc
call gen.bat
go test -v
@echo install [protoc-gen-rpc-go] end
@goto :exit


:protoc-gen-myjson-go
@echo install [protoc-gen-myjson-go] begin
cd %WORK_DIR%\protoc-gen-myjson-go
go install
go generate .\msg
go test -v
@echo install [protoc-gen-myjson-go] end
@goto :exit


:protoc-gen-myjson-ts
@echo install [protoc-gen-myjson-ts] begin
cd %WORK_DIR%\protoc-gen-myjson-ts
go install
go generate
go test -v
@echo install [protoc-gen-myjson-ts] end
@goto :exit


:protoc-gen-mgo-go
@echo install [protoc-gen-mgo-go] begin
cd %WORK_DIR%\protoc-gen-mgo-go
go install
cd model
call gen.bat
go test -v
@echo install [protoc-gen-mgo-go] end
@goto :exit


:protoc-gen-pbex-go
@echo install [protoc-gen-pbex-go] begin
cd %WORK_DIR%\protoc-gen-pbex-go
go install
cd msg
call gen.bat
go test -v
@echo install [protoc-gen-pbex-go] end
@goto :exit


:protoc-gen-pbex-ts
@echo install [protoc-gen-pbex-ts] begin
cd %WORK_DIR%\protoc-gen-pbex-ts
go install
go generate .\msg
@echo install [protoc-gen-pbex-ts] end
@goto :exit


:protoc-gen-client-model-go
@echo install [protoc-gen-client-model-go] begin
cd %WORK_DIR%\protoc-gen-client-model-go
go install
cd model
call gen.bat
go test -v
@echo install [protoc-gen-client-model-go] end
@goto :exit


:trans_file_to_utf8
@echo install [trans_file_to_utf8] begin
cd %WORK_DIR%\trans_file_to_utf8
go install
@echo install [trans_file_to_utf8] end
@goto :exit


:clean-log
del /q /s %WORK_DIR%\protoc-gen-rpc-go\rpc\*.log
del /q /s %WORK_DIR%\protoc-gen-pbex-go\msg\*.log
@goto :exit

:exit
